
function hasClass(obj, cls) {
    return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
}
function addClass(obj, cls) {
    if (!this.hasClass(obj, cls)) obj.className += " " + cls;
}

function removeClass(obj, cls) {
    if (hasClass(obj, cls)) {
        var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
        obj.className = obj.className.replace(reg, ' ');
    }
}
function siblings(elm) {
	var a = [];
	var p = elm.parentNode.children;
	for(var i =0,pl= p.length;i<pl;i++) {
	if(p[i] !== elm) a.push(p[i]);
	}
	return a;
}
window.onload = function(){
	var container = document.querySelector("body");
	 simpScroller(container,{
    	verticalScroll: true,          // 默认垂直滚动
	    horizontalScroll: false,       // 水平滚动，默认false，不水平滚动
	    hideScrollBar: true        // 是否隐藏滚动条      // 滚动时候的回调
	                                   // 支持一个参数，为event对象 
	});
	 var exit1 = document.querySelector(".exit1");
	 var address_layer = document.querySelector(".address-layer");
	 var add_address = document.querySelector(".add-img");
	 exit1.addEventListener(
		"touchstart",
		function() {
			address_layer.style.display = "none";
		}
	);
	 add_address.addEventListener(
		"touchstart",
		function() {
			address_layer.style.display = "block";
		}
	);

	 //计算需要付的总额
	var one_price = document.querySelectorAll(".one-price");
	var sum_price = 0;
	// console.log(one_price.length);
	for(var i = 0;i<one_price.length;i++){
		sum_price = sum_price+parseInt(one_price[i].innerText.slice(1));
	}
	// console.log(sum_price);

	var dot1 = document.querySelector(".dot1");
	var dot2 = document.querySelector(".dot2");
	var pay_button = document.querySelector(".pay-button");
	var span_price = document.querySelector(".span-price");

	//选择支付方式
	dot1.addEventListener(
		"touchstart",
		function() {
			dot2.style.background = "#fff";
			dot1.style.background = "#e81c11";
			pay_button.innerText = "微信支付";
			span_price.innerText = "￥"+sum_price+".00";
		}
	);
	dot2.addEventListener(
		"touchstart",
		function() {
			dot2.style.background = "#e81c11";
			dot1.style.background = "#fff";
			pay_button.innerText = "现金支付";
			span_price.innerText = "￥0.00";
		}
	);

	//把地址添加到储存地址的div内
	var arrow = document.querySelector(".arrow");
	var address_box = document.querySelector(".address-box");
	var exit2 = document.querySelector(".exit2");
	var save = document.querySelector(".save");
	arrow.addEventListener(
		"touchstart",
		function() {
			address_box.style.display = "block";
		}
	);
	exit2.addEventListener(
		"touchstart",
		function() {
			address_box.style.display = "none";
		}
	);
    

	//点击save时,在div内生成ul,li,并且把input内的内容添加到li中。
	var name_input = document.querySelector(".name-input");
	var phone_input = document.querySelector(".phone-input");
	var address_input = document.querySelector(".address-input");
	var address_span = document.querySelector(".address-span");
	save.addEventListener(
		"touchstart",
		function() {
		 	var address_all =name_input.value+","+phone_input.value+","+address_input.value;
		 	address_span.innerText = address_all;
		 	address_layer.style.display = "none";
            document.querySelector(".adrr").value="0";
            //console.log(document.querySelector(".adrr").value);
		}
	);

		//如果没有存地址，显示填写地址提示
		var address_li = document.querySelector(".address-li");
		var warning = document.querySelector(".warning");
		if(!address_li){
			warning.style.display = "block";
		}else{
			warning.style.display = "none";
		}


}